import Vue from 'vue'
import Vuex from 'vuex'

import {
  webTemplateQuery,
  webTemplateDelete,
  webTemplateAdd,
  webTemplateUpdate,
} from '@/api/module/webTemplate'

Vue.use(Vuex)

const state = {}

const getters = {}

const actions = {
  //模板增删改查
  async queryWebTemplate({ commit }, listQuery) {
    let res = await webTemplateQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async deleteWebTemplate({ commit }, row) {
    let res = await webTemplateDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addWebTemplate({ commit }, data) {
    let res = await webTemplateAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateWebTemplate({ commit }, data) {
    let res = await webTemplateUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {}

export default {
  state,
  getters,
  actions,
  mutations,
}
